//
//  RLoginViewControllerc.m
//  EPAa
//
//  Created by lanou3g on 16/4/28.
//  Copyright © 2016年 李日青. All rights reserved.
//

#import "RLoginViewControllerc.h"
#import "RNetWorkRequestManager.h"
#import "RViewController.h"
#import "RHomePageController.h"
#import "RregistViewControllerc.h"
@interface RLoginViewControllerc ()

@end

@implementation RLoginViewControllerc

- (void)viewDidLoad {
    [super viewDidLoad];
       // Do any additional setup after loading the view from its nib.
}
- (IBAction)didClickLoginButton:(id)sender {
        [RNetWorkRequestManager requestURL:[NSURL URLWithString:@"http://api2.pianke.me/user/login"] Method:CK_POST Params:@{@"email":self.emailLabel.text , @"passwd" :self.passwordLabel.text} Result:^(NSData *data, NSURLResponse *response, NSError *error) {
            if (data) {
                NSMutableDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                NSLog(@"%@",jsonDict);
                NSString *str = jsonDict[@"data"][@"msg"];
                if (str) {
                    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:str preferredStyle:UIAlertControllerStyleAlert];
                    UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                    [alertC addAction:alertA];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self presentViewController:alertC animated:YES completion:nil];
                    });
    
                }else {
                 dispatch_async(dispatch_get_main_queue(), ^{
                     [self dismissViewControllerAnimated:YES completion:nil];
                 });
                }
            }
        }];

}

- (IBAction)didClickBackButton:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
    
}
- (IBAction)didClickregistButton:(id)sender {
    RregistViewControllerc *redistVC = [RregistViewControllerc new];
    redistVC.image = ^ (UIImage *image) {
        self.titleimageView.image = image;
    };
    redistVC.label = ^ (NSString *string) {
        self.emailLabel.text = string;
    };
    [self presentViewController:redistVC animated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
